# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

class ApplicationController < ActionController::Base
  helper :all # include all helpers, all the time
  protect_from_forgery # See ActionController::RequestForgeryProtection for details

  # Scrub sensitive parameters from your log
  # filter_parameter_logging :password
  before_filter :get_event
  def get_event
    unless Event.count==0
      #TODO:此处暂时用第一个，后面需要改成标记过关注的会议
      session['event'] = Event.find(:first)
      session['navigation'] = navigation
    end
  end

  def navigation
    nav_hash = Hash.new
    nav_hash.store('events', '会议管理')
    nav_hash.store('users','用户管理')
    nav_hash.store('rooms','房间管理')
    nav_hash.store('dines','宴请管理')
    nav_hash.store('tables','餐桌管理')
    nav_hash.store('trips','行程管理')
    nav_hash.store('top_tables','餐桌分配')

    s = ""
    url = request.path.split('?')
    levels = url[0].split('/')
    levels.each_with_index do |level, index|
      unless level.blank?
        if index == levels.size #|| (level == levels[levels.size-2] && levels[levels.size-1].to_i > 0)
          if nav_hash.key?(level)
            s += "-->#{nav_hash.fetch(level)}"#unless level.to_i > 0
          end
        elsif index==1
        elsif index==2
          s += "<a href='/events/#{levels[index]}'>会议管理</a>"
        elsif levels[index].to_i >0
        else
          link = "/"
          i = 1
          while i <= index
            link += "#{levels[i]}/"
            i+=1
          end
          if nav_hash.key?(level)
            s += "--><a href=\"#{link}\">#{nav_hash.fetch(level)}</a>"
          end
        end
      end
    end
    s
  end
end
